﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YasharEl.Infrastructure.ApplicationModel.Bootstrap.Extensibility
{
    /// <summary>
    /// Generic Bootstrapping extension host with default fifo implementation.
    /// </summary>
    /// <typeparam name="TExtension">The type of the extension.</typeparam>
    public class FifoBasedExtensionHost<TExtension> : IBootstrappingExtensionHost<TExtension>
        where TExtension : IBootstrappingExtension
    {
        #region Fields

        private readonly Queue<TExtension> extensions;

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FifoBasedExtensionHost{TExtension}"/> class.
        /// </summary>
        public FifoBasedExtensionHost()
        {
            this.extensions = new Queue<TExtension>();
        }

        #endregion

        #region IBootstrappingExtensionHost<TExtension> Implementations

        /// <summary>
        /// Gets the extensions.
        /// </summary>
        public IEnumerable<TExtension> Extensions
        {
            get
            {
                return this.extensions;
            }
        }

        /// <summary>
        /// Adds the extension to the bootstrapping mechanism. The extensions are executed in the order which they were
        /// added.
        /// </summary>
        /// <param name="extension">The extension to be added.</param>
        public void AddExtension(TExtension extension)
        {
            this.extensions.Enqueue(extension);
        }

        #endregion
    }
}
